(function () {
    /**
     * 扑克牌扩展函数
     * @class CardUI
     * @constructor
     */
    function CardUI(cardInfo, halfPass) {
        CardUI.super(this);

        this.cardType  = null;
        this.cardPoint = null;
        this.cardInfo  = cardInfo;
        this._selected = false;
        this._point = null;
        this._enableClick = false;

        cardInfo && this.change(cardInfo);
        if(halfPass){
            this.halfPass();
        }
        this.bindEvent();
    }
    Laya.class(CardUI, "ui.Com.Card", ui.Room.UI.CardUI);

    var _proto = CardUI.prototype;
    /**
     * 扑克牌字符对应关系
     * key : 与后台约定扑克牌的值：2,3,4,5,6,7,8,9,10,11,12,13,14对应2,3,4,5,6,7,8,9,10,J,Q,K,A
     * value : 与自定义BitMapFont对应的字符 红色大写，黑色小写
     */
    _proto.pointMap = {
        "2"  : "b",
        "3"  : "c",
        "4"  : "d",
        "5"  : "e",
        "6"  : "f",
        "7"  : "g",
        "8"  : "h",
        "9"  : "i",
        "10" : "j",
        "11" : "k",
        "12" : "l",
        "13" : "m",
        "14" : "a"
    };
    /**
     * @privite
     * 绑定事件
     */
    _proto.bindEvent = function () {
        this.on(Laya.Event.CLICK, this, function () {
            if(!this._enableClick){return;}
            if(this._selected){
                this.selected = false;
            }else{
                this.selected = true;
            }
        });
    }
    /**
     * @privite
     * 改变扑克牌的牌型
     */
    _proto.change = function (cardInfo) {
        this._point = cardInfo;

        this.cardType = cardInfo.slice(0, 1).toUpperCase();
        this.cardPoint = cardInfo.slice(1);

        var trueText = this.pointMap[this.cardPoint];
        if(this.cardType === "H" || this.cardType === "D"){
            trueText = trueText.toUpperCase();
            this.pointNum.changeText(trueText);
        }else{
            trueText = trueText.toLowerCase();
            this.pointNum.changeText(trueText);
        }

        this.typeSmall.changeText(this.cardType);
        this.typeBig.changeText(this.cardType);
    }
    /**
     * @public
     * 翻牌
     */
    _proto.halfPass = function () {
        this.front.visible = true;
        this.back.visible = false;
    }

    /**
     * @property
     * get:获取扑克牌的选中状态
     * set:设置扑克牌是否选择 可选true或false
     */
    Laya.getset(0, _proto, "selected", function (){
        return this._selected;
    }, function (value) {
        this._selected = value;
        this.cover.visible = this._selected;
    });

    /**
     * @property
     * get:获取扑克牌当前牌型
     * set:设置扑克牌的牌型
     */
    Laya.getset(0, _proto, "point", function () {
        return this._point;
    }, function (value) {
        this.change(value);
    });

    /**
     * @property
     * get:获取扑克牌是否允许点击
     * set:设置扑克牌是否允许点击
     */
    Laya.getset(0, _proto, "enableclick", function () {
        return this._enableClick;
    }, function (value) {
        this._enableClick = value;
    });
})();